package prvydevj;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created with IntelliJ IDEA.
 * User: TOM
 * Date: 9.6.13
 * Time: 20:56
 * To change this template use File | Settings | File Templates.
 */
public class EditDetailsForm {
    private JTextField jmeno;
    private JTextField ulice;
    private JTextField mesto;
    private JTextField psc;
    private JTextField ico;
    private JTextField dic;
    private JTextField ucet;
    private JButton save;
    private JPanel mainPanel;

    public EditDetailsForm(final InvoiceManager manager) {

        jmeno.setText(manager.getOwnerName());
        ulice.setText(manager.getOwnerAddress());
        mesto.setText(manager.getOwnerCity());
        psc.setText(manager.getOwnerPsc());
        ico.setText(manager.getOwnerIco());
        dic.setText(manager.getOwnerDic());
        ucet.setText(manager.getOwnerAccount());

        save.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                manager.setOwnerDetails(jmeno.getText(), ulice.getText(), mesto.getText(), psc.getText(), ico.getText(), dic.getText(), ucet.getText());
                Container frame = save.getParent();
                do
                    frame = frame.getParent();
                while (!(frame instanceof JFrame));
                ((JFrame) frame).dispose();
            }
        });
    }

    public static void Show(InvoiceManager manager) {
        final EditDetailsForm form = new EditDetailsForm(manager);
        JFrame frame = new JFrame("Osobni udaje ");

        frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        frame.setContentPane(form.mainPanel);

        frame.setPreferredSize(new Dimension(400, 300));
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);

    }
}
